package com.shujia.day12;

import java.io.*;
import java.util.Arrays;

public class Demo12BuffedInputStream {
    public static void main(String[] args) throws IOException {
        /*
            缓冲流：
                字节缓冲输入流 BuffedInputStream
                字节缓冲输出流 BuffedOutputStream

         */
        String path = "data/th.jpg";
        String outPath = "data/buffered.jpg";
        BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(path));
        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(outPath));

        int capacityLen = 100;
        // 一般情况下，为了使用效率考虑，都会使用字节数组的方式读取数据
        byte[] bytes = new byte[capacityLen];
        int readLen = 0;
        while ((readLen = bufferedInputStream.read(bytes))>0){
//            if (readLen < capacityLen) {
//                System.out.println("获取的数据长度:"+readLen+"\t"+ Arrays.toString(Arrays.copyOf(bytes, readLen)));
//            }else {
//                System.out.println("获取的数据长度:"+readLen+"\t"+Arrays.toString(bytes));
//            }
            bufferedOutputStream.write(bytes,0,readLen);
        }
        bufferedInputStream.close();
        bufferedOutputStream.close();

    }
}
